home *** CD-ROM | disk | FTP | other *** search
- { lengthy.pas -- Show hourglass cursor during a lengthy operation }
-
- program Lengthy;
-
- {$R lengthy.res}
-
- uses WinTypes, WinProcs, WObjects;
-
- const
-
- timer_ID = 1; { Timer ID value }
- timer_Interval = 1; { Timer interval in seconds }
- id_Menu = 100; { Menu resource ID }
- cm_Start = 101; { Start command ID }
- max_Time = 10; { Length of pseudo operation in seconds }
-
- type
-
- LengthyApplication = object(TApplication)
- procedure InitMainWindow; virtual;
- end;
-
- PLengthyWindow = ^LengthyWindow;
- LengthyWindow = object(TWindow)
- TimeRemaining: Integer;
- constructor Init(AParent: PWindowsObject; ATitle: PChar);
- procedure ShowTime;
- procedure CMStart(var Msg: TMessage);
- virtual cm_First + cm_Start;
- procedure WMTimer(var Msg: TMessage);
- virtual wm_First + wm_Timer;
- end;
-
-
- { LengthyApplication }
-
- {- Initialize LengthyApplication object's window }
- procedure LengthyApplication.InitMainWindow;
- begin
- MainWindow := New(PLengthyWindow, Init(nil, 'Lengthy'))
- end;
-
-
- { LengthyWindow }
-
- {- Construct LengthyWindow object }
- constructor LengthyWindow.Init(AParent: PWindowsObject;
- ATitle: PChar);
- begin
- TWindow.Init(AParent, ATitle);
- Attr.Menu := LoadMenu(HInstance, PChar(id_Menu))
- end;
-
- {- Display time remaining }
- procedure LengthyWindow.ShowTime;
- var
- S: string[30];
- DC: HDC;
- begin
- Str(TimeRemaining, S);
- S := 'Time remaining = ' + S + ' ';
- DC := GetDC(HWindow);
- TextOut(DC, 20, 50, @S[1], Length(S));
- ReleaseDC(HWindow, DC);
- MessageBeep(0)
- end;
-
- {- Start pseudo lengthy operation }
- procedure LengthyWindow.CMStart(var Msg: TMessage);
- begin
- SetCursor(LoadCursor(0, idc_Wait));
- SetCapture(HWindow);
- SetTimer(hWindow, timer_ID, timer_Interval * 1000, nil);
- TimeRemaining := max_Time;
- ShowTime
- end;
-
- {- Intercept timer events and display hourglass cursor }
- procedure LengthyWindow.WMTimer(var Msg: TMessage);
- begin
- Dec(TimeRemaining);
- ShowTime;
- if TimeRemaining <= 0 then
- begin
- KillTimer(hWindow, timer_ID);
- SetCursor(LoadCursor(0, idc_Arrow));
- ReleaseCapture;
- MessageBox(HWindow, 'Operation completed', 'Message', mb_Ok)
- end
- end;
-
- var
-
- LengthyApp: LengthyApplication;
-
- begin
- LengthyApp.Init('LengthyApp');
- LengthyApp.Run;
- LengthyApp.Done
- end.
-
-
- {--------------------------------------------------------------
- Copyright (c) 1991 by Tom Swan. All rights reserved.
- Revision 1.00 Date: 4/17/1991
- ---------------------------------------------------------------}
-